package com.example.employeemanagementsystem.service;

import com.example.employeemanagementsystem.model.Employee;
import com.example.employeemanagementsystem.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {

    @Autowired
    private EmployeeRepository employeeRepository;

    public boolean addEmployee(Employee employee) {
        employeeRepository.save(employee);
        return true;
    }

    public boolean updateEmployee(String employeeNumber, Employee employee) {
        if (employeeRepository.existsById(employeeNumber)) {
            employee.setEmployeeNumber(employeeNumber);
            employeeRepository.save(employee);
            return true;
        }
        return false;
    }

    public boolean deleteEmployee(String employeeNumber) {
        employeeRepository.deleteById(employeeNumber);
        return true;
    }

    public List<Employee> getAllEmployees() {
        return employeeRepository.findAll();
    }
}